package org.example.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.example.bean.Orderdetail;
import org.example.bean.Orders;

import java.util.List;

public interface OrdersMapper extends BaseMapper<Orders> {
    @Select("select ods.*,a.recipient_name,a.phone,a.detailed_address,\n" +
            "        p.product_name,p.main_url,p.description, p.price, od.count\n" +
            "from orders ods\n" +
            "left join orderdetail od on ods.order_id = od.order_id\n" +
            "left join product p on od.product_id = p.product_id\n" +
            "left join address a on ods.address_id=a.address_id\n" +
            "where ods.order_status = ${status1}\n" +
            "order by ods.order_id desc")
    @Results({
            //property需要严格对照bean类的信息
            @Result(column = "item_id", property = "orderdetail.item_id"),
            @Result(column = "order_id", property = "order_id"),
            @Result(column = "user_id", property = "user_id"),
            @Result(column = "address_id", property = "address_id"),
            @Result(column = "order_time", property = "order_time"),
            @Result(column = "order_status", property = "order_status"),
            @Result(column = "recipient_name", property = "address.recipient_name"),
            @Result(column = "phone", property = "address.phone"),
            @Result(column = "detailed_address", property = "address.detailed_address"),
            @Result(column = "product_name", property = "product.product_name"),
            @Result(column = "main_url", property = "product.main_url"),
            @Result(column = "description", property = "product.description"),
            @Result(column = "price", property = "orderdetail.current_price"),
            @Result(column = "count", property = "orderdetail.count")
    })
    //多个参数，@Param("参数名")
    List<Orders> selectByOrderStatusWithProduct(@Param("status1") Integer orderStatus1);

    @Select("select ods.*,od.item_id ,p.product_name,p.main_url,p.description, p.price, od.count\n" +
            "from orders ods\n" +
            "left join orderdetail od on ods.order_id = od.order_id\n" +
            "left join product p on od.product_id = p.product_id\n" +
            "where ods.order_id = #{order_id}\n" +
            "order by ods.order_id desc;")
    @Results({
            //property需要严格对照bean类的信息
            @Result(column = "item_id", property = "orderdetail.item_id"),
            @Result(column = "order_id", property = "order_id"),
            @Result(column = "user_id", property = "user_id"),
            @Result(column = "address_id", property = "address_id"),
            @Result(column = "order_time", property = "order_time"),
            @Result(column = "order_status", property = "order_status"),
            @Result(column = "product_name", property = "product.product_name"),
            @Result(column = "main_url", property = "product.main_url"),
            @Result(column = "description", property = "product.description"),
            @Result(column = "price", property = "orderdetail.current_price"),
            @Result(column = "count", property = "orderdetail.count")
    })
    List<Orders> selectByOrderIdWithProduct(@Param("order_id") Integer order_id);


}
